Type.registerNamespace('ScottCate');

ScottCate.IHighPerformance = function() {}
ScottCate.IHighPerformance.Prototype = { MPHOver100: function() {} }
ScottCate.IHighPerformance.registerInterface('ScottCate.IHighPerformance');

ScottCate.Automobile = function(color) {
    this._color = color;
    this._maxSpeed = 0;
    this._numberOfWheels = 4;
}
ScottCate.Automobile.prototype = {
    get_color: function() { return this._color; },
    get_maxSpeed: function() {return this._maxSpeed; },
    get_wheelCount: function() { return this._numberOfWheels; }
}

ScottCate.CheapCar = function(color) {
    ScottCate.CheapCar.initializeBase(this, [color]);
    this._maxSpeed = 55;
}
ScottCate.Corvette = function(color) {
    ScottCate.Corvette.initializeBase(this, [color]);
    this._maxSpeed = 155;
}
ScottCate.Corvette.prototype.MPHOver100 = function() {
    return this._maxSpeed - 100;
}
ScottCate.Ferrari = function(color) {
    ScottCate.Ferrari.initializeBase(this, [color]);
    this._maxSpeed = 255;
}
ScottCate.Ferrari.prototype.MPHOver100 = function() {
    return this._maxSpeed - 100;
}
ScottCate.Dumptruck = function(color) {
    ScottCate.Dumptruck.initializeBase(this, [color]);
    this._maxSpeed = 15;
}
ScottCate.Motorcycle = function(color) {
    ScottCate.Motorcycle.initializeBase(this, [color]);
    this._maxSpeed = 65;
    this._numberOfWheels = 2;
}
ScottCate.SpeedBike = function(color) {
    ScottCate.SpeedBike.initializeBase(this, [color]);
    this._maxSpeed = 233;
}
ScottCate.SpeedBike.prototype.MPHOver100 = function() {
    return this._maxSpeed - 100;
}

ScottCate.Automobile.registerClass('ScottCate.Automobile', null, Sys.IDisposable);
ScottCate.CheapCar.registerClass('ScottCate.CheapCar', ScottCate.Automobile);
ScottCate.Corvette.registerClass('ScottCate.Corvette', ScottCate.Automobile, ScottCate.IHighPerformance);

//can also implement multiple interfaces, as the third param is
//listed as a Param[] of Interfaces, just list them one after the other
//Sample registering ScottCate.IHighPerformance and ScottCate.IAnotherInterface
//ScottCate.Ferrari.registerClass('ScottCate.Ferrari', ScottCate.Automobile, ScottCate.IHighPerformance, ScottCate.IAnotherInterface);
ScottCate.Ferrari.registerClass('ScottCate.Ferrari', ScottCate.Automobile, ScottCate.IHighPerformance);

ScottCate.Dumptruck.registerClass('ScottCate.Dumptruck', ScottCate.Automobile);
ScottCate.Motorcycle.registerClass('ScottCate.Motorcycle', ScottCate.Automobile);
ScottCate.SpeedBike.registerClass('ScottCate.SpeedBike', ScottCate.Motorcycle, ScottCate.IHighPerformance);

function IsHighPerformance(auto) {
    var speed = $get('speed');
    var sb = new Sys.StringBuilder('<div>');
    
    var isHighPerformance = ScottCate.IHighPerformance.isImplementedBy(auto);
    WriteLineToStringBuilder(sb, 'Can ' + Object.getTypeName(auto) + ' drive over 100MPH? ', isHighPerformance );
    
    if(isHighPerformance) {
        WriteLineToStringBuilder(sb, 'How fast over 100MPH? ', GetMPHOver100(auto) );
        WriteLineToStringBuilder(sb, 'And has a top speed of : ', auto.get_maxSpeed() );
    }
    sb.append(' </div>');
    speed.innerHTML = sb.toString();
}

function GetMPHOver100(IHighPerformance) {
    return IHighPerformance.MPHOver100();
}

function WriteLineToStringBuilder(sb, label, value) {
    sb.append(String.format("<b>{0} : </b> {1} <br />", label, value));
}

function ClearTest() {
    var speed = $get('speed');
    speed.innerHTML = '';
}









